home *** CD-ROM | disk | FTP | other *** search
- Path: s02.pavilion.co.uk!usenet
- From: AJRobb@pavilion.co.uk (Andy J Robb)
- Newsgroups: comp.lang.c
- Subject: Re: Standard question - pointer initialization
- Date: Tue, 12 Mar 1996 23:47:03 GMT
- Organization: Pavilion Internet plc
- Message-ID: <4i52bk$5el@s02.pavilion.co.uk>
- References: <4hk9un$906@hammer.msfc.nasa.gov>
- NNTP-Posting-Host: poolc27.pavilion.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Brian.Day@msfc.nasa.gov (Brian Day) wrote:
-
- >Hi all,
-
- >I don't have a copy of the ANSI standard handy, and was wondering
- >if y'all could answer a question for me.
-
- >We were recently handed a coding standard which said:
-
- > "Always initialize pointers when they are declared"
-
- >Doesn't the standard say something about some pointers
- >being automatically initialized to NULL, or something like that?
-
- -----BEGIN PGP SIGNED MESSAGE-----
-
- Off the top of my head, the only time pointers are initialized to NULL
- is if they are global or static.
-
- The use of calloc() allows a list of NULL initialized pointers to be
- generated. It is a good idea while code is being developed as it
- allows dereferencing of a NULL pointer to crash the program earlier
- rather than later. I sympathize with another poster, it makes the
- code slower/larger. Often, the program should behave identically if
- initialized or not. However, initializing a pointer to NULL will
- prevent a compiler from detecting an "uninitialize pointer" - so you
- can be passing NULL pointers around to create a bombshell elsewhere.
-
- To make this strategy work reliably, you need to be able to delay the
- definition of the pointer until later in the body of the code. This
- may prompt a move to C++. Some people LIKE to have all variables
- declared at the beginning of the code - even if their values cannot be
- defined until later. Thus manifestly const values get held in
- variables, etc.
-
- Regards,
- Andy Robb.
-
- -----BEGIN PGP SIGNATURE-----
- Version: 2.6.2i
-
- iQCVAwUBMUYIu5Pl4P16x9sNAQEI3wQAqAdigkCPwXfT7u3Ti4GcfMJK/TkNVHIa
- yBc/h0nPOFxD0bZ89B6m68dZpbo+WTs1crju2Pk/9wTqzn46ZtS3zuYWwUQZ4Ivm
- J4sYXrY4JvvKgQ+AVOqJ0RS0yGjXu+cl/LL558S6eTLSbrbqd5E1/mu15aiFqDRF
- lAzoenljTwg=
- =KzJs
- -----END PGP SIGNATURE-----
-
- -----BEGIN PGP PUBLIC KEY BLOCK-----
- Version: 2.6.2i
-
- mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
- MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
- B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
- tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
- IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
- =/wVD
- -----END PGP PUBLIC KEY BLOCK-----
-
-